﻿using EnglishAuction.BUS;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace EnglishAuction
{
    public partial class AccountInfo : System.Web.UI.Page
    {

        private void fillData()
        {
            NguoiDung nguoiDung = (NguoiDung)Session["CurrentUser"];
            lbTenTaiKhoan.Text = nguoiDung.TaiKhoan;
            txtCMND.Text = nguoiDung.CMND;
            txtDiaChi.Text = nguoiDung.DiaChi;
            txtEmail.Text = nguoiDung.Email;
            txtHoTen.Text = nguoiDung.HoTen;
            txtNgaySinh.Text = String.Format("{0:MM/dd/yyyy}", nguoiDung.NgaySinh);
            txtSoDienThoai.Text = nguoiDung.SoDienThoai;
            if (nguoiDung.GioiTinh == true)
                rbNam.Checked = true;
            else
                rbNu.Checked = true;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["CurrentUser"] == null)
                {
                    Response.Redirect("Login.aspx");
                }
                else
                {
                    fillData();
                }
            }

        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            NguoiDung nguoiDung = (NguoiDung)Session["CurrentUser"];
            nguoiDung.CMND = txtCMND.Text;
            nguoiDung.DiaChi = txtDiaChi.Text;
            nguoiDung.Email = txtEmail.Text;
            nguoiDung.HoTen = txtHoTen.Text;
            nguoiDung.NgaySinh = DateTime.Parse(txtNgaySinh.Text);
            if (rbNam.Checked)
                nguoiDung.GioiTinh = true;
            else
                nguoiDung.GioiTinh = false;
            nguoiDung.SoDienThoai = txtSoDienThoai.Text;

            NguoiDungBUS.Update(nguoiDung);

            fillData();
            lbThongBao.Text = "Cập Nhật Thông Tìn Tài Khoản Thành Công";
        }
    }
}